package com.zjut.an.acquisition.dao;

import java.sql.Timestamp;

import org.apache.commons.lang.StringUtils;

/**
 * AnAcquisition entity. @author MyEclipse Persistence Tools
 */

public class AnAcquisition implements java.io.Serializable {

	// Fields
	private static final long serialVersionUID = 1L;
	/**
	 * 动态页翻页页号
	 */
	public static final String PAGE = "[page]";
	/**
	 * 停止状态
	 */
	public static final int STOP = 0;
	/**
	 * 采集状态
	 */
	public static final int START = 1;
	/**
	 * 暂停状态
	 */
	public static final int PAUSE = 2;
	
	public static enum AcquisitionResultType {
		SUCCESS, TITLESTARTNOTFOUND, TITLEENDNOTFOUND, CONTENTSTARTNOTFOUND, CONTENTENDNOTFOUND,VIEWSTARTNOTFOUND,VIEWENDNOTFOUND,AUTHORSTARTNOTFOUND,AUTHORENDNOTFOUND,ORIGINSTARTNOTFOUND,ORIGINENDNOTFOUND,DESCRISTARTNOTFOUND,DESCRIENDNOTFOUND, RELEASESTARTNOTFOUND,RELEASEENDNOTFOUND,VIEWIDSTARTNOTFOUND,VIEWIDENDNOTFOUND,TITLEEXIST, URLEXIST, UNKNOW
	}
	
	private Integer acId; //acquision
	private Integer wcId; //webcalss
	private Integer adId; //admin
	private String acqName;
	private Timestamp startTime;
	private Timestamp endTime;
	private Integer status;
	private Integer currNum;
	private Integer currItem;
	private Integer totalItem;
	private Integer totalNum;
	private Integer pauseTime;
	private String pageEncoding;
	private String planList;
	private String dynamicAddr;
	private Integer dynamicStart;
	private Integer dynamicEnd;
	private String linksetStart;
	private String linksetEnd;
	private String linkStart;
	private String linkEnd;
	private String titleStart;
	private String titleEnd;
	private String keywordsStart;
	private String keywordsEnd;
	private String descriptionStart;
	private String descriptionEnd;
	private String contentStart;
	private String contentEnd;
	private String paginationStart;
	private String paginationEnd;
	private Integer queue;
	private Boolean imgAcqu;
	private String contentPrefix;
	private String imgPrefix;
	private String viewStart;
	private String viewEnd;
	private String viewIdStart;
	private String viewIdEnd;
	private String viewLink;
	private String releaseTimeStart;
	private String releaseTimeEnd;
	private String authorStart;
	private String authorEnd;
	private String originStart;
	private String originEnd;
	private String releaseTimeFormat;

	// Constructors

	/** default constructor */
	public AnAcquisition() {
	}
	
	public AnAcquisition(Integer acId) {
		this.acId = acId;
	}

	/** minimal constructor */
	public AnAcquisition(Integer wcId, Integer adId, String acqName,
			Integer status, Integer currNum, Integer currItem,
			Integer totalItem, Integer pauseTime, String pageEncoding,
			Integer queue,  Boolean imgAcqu) {
		this.wcId = wcId;
		this.adId = adId;
		this.acqName = acqName;
		this.status = status;
		this.currNum = currNum;
		this.currItem = currItem;
		this.totalItem = totalItem;
		this.pauseTime = pauseTime;
		this.pageEncoding = pageEncoding;
		this.queue = queue;
		this.imgAcqu = imgAcqu;
	}

	/** full constructor */
	public AnAcquisition(Integer wcId, Integer adId, String acqName,
			Timestamp startTime, Timestamp endTime, Integer status,
			Integer currNum, Integer currItem, Integer totalItem,
			Integer pauseTime, String pageEncoding, String planList,
			String dynamicAddr, Integer dynamicStart, Integer dynamicEnd,
			String linksetStart, String linksetEnd, String linkStart,
			String linkEnd, String titleStart, String titleEnd,
			String keywordsStart, String keywordsEnd, String descriptionStart,
			String descriptionEnd, String contentStart, String contentEnd,
			String paginationStart, String paginationEnd, Integer queue,
			Boolean imgAcqu, String contentPrefix,
			String imgPrefix, String viewStart, String viewEnd,
			String viewIdStart, String viewIdEnd, String viewLink,
			String releaseTimeStart, String releaseTimeEnd, String authorStart,
			String authorEnd, String originStart, String originEnd,
			String releaseTimeFormat) {
		this.wcId = wcId;
		this.adId = adId;
		this.acqName = acqName;
		this.startTime = startTime;
		this.endTime = endTime;
		this.status = status;
		this.currNum = currNum;
		this.currItem = currItem;
		this.totalItem = totalItem;
		this.pauseTime = pauseTime;
		this.pageEncoding = pageEncoding;
		this.planList = planList;
		this.dynamicAddr = dynamicAddr;
		this.dynamicStart = dynamicStart;
		this.dynamicEnd = dynamicEnd;
		this.linksetStart = linksetStart;
		this.linksetEnd = linksetEnd;
		this.linkStart = linkStart;
		this.linkEnd = linkEnd;
		this.titleStart = titleStart;
		this.titleEnd = titleEnd;
		this.keywordsStart = keywordsStart;
		this.keywordsEnd = keywordsEnd;
		this.descriptionStart = descriptionStart;
		this.descriptionEnd = descriptionEnd;
		this.contentStart = contentStart;
		this.contentEnd = contentEnd;
		this.paginationStart = paginationStart;
		this.paginationEnd = paginationEnd;
		this.queue = queue;
		this.imgAcqu = imgAcqu;
		this.contentPrefix = contentPrefix;
		this.imgPrefix = imgPrefix;
		this.viewStart = viewStart;
		this.viewEnd = viewEnd;
		this.viewIdStart = viewIdStart;
		this.viewIdEnd = viewIdEnd;
		this.viewLink = viewLink;
		this.releaseTimeStart = releaseTimeStart;
		this.releaseTimeEnd = releaseTimeEnd;
		this.authorStart = authorStart;
		this.authorEnd = authorEnd;
		this.originStart = originStart;
		this.originEnd = originEnd;
		this.releaseTimeFormat = releaseTimeFormat;
	}
	
	public void init() {
		if (getStatus() == null) {
			setStatus(STOP);
		}
		if (getCurrNum() == null) {
			setCurrNum(0);
		}
		if (getCurrItem() == null) {
			setCurrItem(0);
		}
		if (getTotalItem() == null) {
			setTotalItem(0);
		}
		if (getPauseTime() == null) {
			setPauseTime(0);
		}
		if(getQueue()==null){
			setQueue(0);
		}
	}
	
	/**
	 * 是否停止
	 * 
	 * @return
	 */
	public boolean isStop() {
		int status = getStatus();
		return status == 0;
	}

	/**
	 * 是否暂停
	 * 
	 * @return
	 */
	public boolean isPuase() {
		int status = getStatus();
		return status == 2;
	}

	/**
	 * 是否中断。停止和暂停都需要中断。
	 * 
	 * @return
	 */
	public boolean isBreak() {
		int status = getStatus();
		return status == 0 || status == 2;
	}

	public String[] getPlans() {
		String plan = getPlanList();
		if (!StringUtils.isBlank(plan)) {
			return StringUtils.split(plan);
		} else {
			return new String[0];
		}
	}

	public String[] getAllPlans() {
		String[] plans = getPlans();
		Integer start = getDynamicStart();
		Integer end = getDynamicEnd();
		if (!StringUtils.isBlank(getDynamicAddr()) && start != null
				&& end != null && start >= 0 && end >= start) {
			int plansLen = plans.length;
			String[] allPlans = new String[plansLen + end - start + 1];
			for (int i = 0; i < plansLen; i++) {
				allPlans[i] = plans[i];
			}
			for (int i = 0, len = end - start + 1; i < len; i++) {
				allPlans[plansLen + i] = getDynamicAddrByNum(start + i);
			}
			return allPlans;
		} else {
			return plans;
		}
	}

	public String getDynamicAddrByNum(int num) {
		return StringUtils.replace(getDynamicAddr(), PAGE, String.valueOf(num));
	}

	public int getTotalNum() {
		int count = 0;
		Integer start = getDynamicStart();
		Integer end = getDynamicEnd();
		if (!StringUtils.isBlank(getDynamicAddr()) && start != null
				&& end != null) {
			count = end - start + 1;
		}
		if (!StringUtils.isBlank(getPlanList())) {
			count += getPlans().length;
		}
		return count;
	}

	// Property accessors

	public Integer getAcId() {
		return this.acId;
	}

	public void setAcId(Integer acId) {
		this.acId = acId;
	}

	public Integer getWcId() {
		return this.wcId;
	}

	public void setWcId(Integer wcId) {
		this.wcId = wcId;
	}

	public Integer getAdId() {
		return this.adId;
	}

	public void setAdId(Integer adId) {
		this.adId = adId;
	}

	public String getAcqName() {
		return this.acqName;
	}

	public void setAcqName(String acqName) {
		this.acqName = acqName;
	}

	public Timestamp getStartTime() {
		return this.startTime;
	}

	public void setStartTime(Timestamp startTime) {
		this.startTime = startTime;
	}

	public Timestamp getEndTime() {
		return this.endTime;
	}

	public void setEndTime(Timestamp endTime) {
		this.endTime = endTime;
	}

	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getCurrNum() {
		return this.currNum;
	}

	public void setCurrNum(Integer currNum) {
		this.currNum = currNum;
	}

	public Integer getCurrItem() {
		return this.currItem;
	}

	public void setCurrItem(Integer currItem) {
		this.currItem = currItem;
	}

	public Integer getTotalItem() {
		return this.totalItem;
	}

	public void setTotalItem(Integer totalItem) {
		this.totalItem = totalItem;
	}

	public Integer getPauseTime() {
		return this.pauseTime;
	}

	public void setPauseTime(Integer pauseTime) {
		this.pauseTime = pauseTime;
	}

	public String getPageEncoding() {
		return this.pageEncoding;
	}

	public void setPageEncoding(String pageEncoding) {
		this.pageEncoding = pageEncoding;
	}

	public String getPlanList() {
		return this.planList;
	}

	public void setPlanList(String planList) {
		this.planList = planList;
	}

	public String getDynamicAddr() {
		return this.dynamicAddr;
	}

	public void setDynamicAddr(String dynamicAddr) {
		this.dynamicAddr = dynamicAddr;
	}

	public Integer getDynamicStart() {
		return this.dynamicStart;
	}

	public void setDynamicStart(Integer dynamicStart) {
		this.dynamicStart = dynamicStart;
	}

	public Integer getDynamicEnd() {
		return this.dynamicEnd;
	}

	public void setDynamicEnd(Integer dynamicEnd) {
		this.dynamicEnd = dynamicEnd;
	}

	public String getLinksetStart() {
		return this.linksetStart;
	}

	public void setLinksetStart(String linksetStart) {
		this.linksetStart = linksetStart;
	}

	public String getLinksetEnd() {
		return this.linksetEnd;
	}

	public void setLinksetEnd(String linksetEnd) {
		this.linksetEnd = linksetEnd;
	}

	public String getLinkStart() {
		return this.linkStart;
	}

	public void setLinkStart(String linkStart) {
		this.linkStart = linkStart;
	}

	public String getLinkEnd() {
		return this.linkEnd;
	}

	public void setLinkEnd(String linkEnd) {
		this.linkEnd = linkEnd;
	}

	public String getTitleStart() {
		return this.titleStart;
	}

	public void setTitleStart(String titleStart) {
		this.titleStart = titleStart;
	}

	public String getTitleEnd() {
		return this.titleEnd;
	}

	public void setTitleEnd(String titleEnd) {
		this.titleEnd = titleEnd;
	}

	public String getKeywordsStart() {
		return this.keywordsStart;
	}

	public void setKeywordsStart(String keywordsStart) {
		this.keywordsStart = keywordsStart;
	}

	public String getKeywordsEnd() {
		return this.keywordsEnd;
	}

	public void setKeywordsEnd(String keywordsEnd) {
		this.keywordsEnd = keywordsEnd;
	}

	public String getDescriptionStart() {
		return this.descriptionStart;
	}

	public void setDescriptionStart(String descriptionStart) {
		this.descriptionStart = descriptionStart;
	}

	public String getDescriptionEnd() {
		return this.descriptionEnd;
	}

	public void setDescriptionEnd(String descriptionEnd) {
		this.descriptionEnd = descriptionEnd;
	}

	public String getContentStart() {
		return this.contentStart;
	}

	public void setContentStart(String contentStart) {
		this.contentStart = contentStart;
	}

	public String getContentEnd() {
		return this.contentEnd;
	}

	public void setContentEnd(String contentEnd) {
		this.contentEnd = contentEnd;
	}

	public String getPaginationStart() {
		return this.paginationStart;
	}

	public void setPaginationStart(String paginationStart) {
		this.paginationStart = paginationStart;
	}

	public String getPaginationEnd() {
		return this.paginationEnd;
	}

	public void setPaginationEnd(String paginationEnd) {
		this.paginationEnd = paginationEnd;
	}

	public Integer getQueue() {
		return this.queue;
	}

	public void setQueue(Integer queue) {
		this.queue = queue;
	}

	public Boolean getImgAcqu() {
		return this.imgAcqu;
	}

	public void setImgAcqu(Boolean imgAcqu) {
		this.imgAcqu = imgAcqu;
	}

	public String getContentPrefix() {
		return this.contentPrefix;
	}

	public void setContentPrefix(String contentPrefix) {
		this.contentPrefix = contentPrefix;
	}

	public String getImgPrefix() {
		return this.imgPrefix;
	}

	public void setImgPrefix(String imgPrefix) {
		this.imgPrefix = imgPrefix;
	}

	public String getViewStart() {
		return this.viewStart;
	}

	public void setViewStart(String viewStart) {
		this.viewStart = viewStart;
	}

	public String getViewEnd() {
		return this.viewEnd;
	}

	public void setViewEnd(String viewEnd) {
		this.viewEnd = viewEnd;
	}

	public String getViewIdStart() {
		return this.viewIdStart;
	}

	public void setViewIdStart(String viewIdStart) {
		this.viewIdStart = viewIdStart;
	}

	public String getViewIdEnd() {
		return this.viewIdEnd;
	}

	public void setViewIdEnd(String viewIdEnd) {
		this.viewIdEnd = viewIdEnd;
	}

	public String getViewLink() {
		return this.viewLink;
	}

	public void setViewLink(String viewLink) {
		this.viewLink = viewLink;
	}

	public String getReleaseTimeStart() {
		return this.releaseTimeStart;
	}

	public void setReleaseTimeStart(String releaseTimeStart) {
		this.releaseTimeStart = releaseTimeStart;
	}

	public String getReleaseTimeEnd() {
		return this.releaseTimeEnd;
	}

	public void setReleaseTimeEnd(String releaseTimeEnd) {
		this.releaseTimeEnd = releaseTimeEnd;
	}

	public String getAuthorStart() {
		return this.authorStart;
	}

	public void setAuthorStart(String authorStart) {
		this.authorStart = authorStart;
	}

	public String getAuthorEnd() {
		return this.authorEnd;
	}

	public void setAuthorEnd(String authorEnd) {
		this.authorEnd = authorEnd;
	}

	public String getOriginStart() {
		return this.originStart;
	}

	public void setOriginStart(String originStart) {
		this.originStart = originStart;
	}

	public String getOriginEnd() {
		return this.originEnd;
	}

	public void setOriginEnd(String originEnd) {
		this.originEnd = originEnd;
	}

	public String getReleaseTimeFormat() {
		return this.releaseTimeFormat;
	}

	public void setReleaseTimeFormat(String releaseTimeFormat) {
		this.releaseTimeFormat = releaseTimeFormat;
	}

}